package com.example.lab2cv;

import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class Contact extends Fragment implements View.OnClickListener {
	private static View view;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.sendEmail:

			Intent intent = new Intent(Intent.ACTION_SEND);
			intent.setType("plain/text");
			intent.putExtra(intent.EXTRA_EMAIL,
					new String[] { "wizards@hasbro.co.uk" });
			intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
			intent.putExtra(Intent.EXTRA_TEXT, "What does a deck of magic cost");
			startActivity(Intent.createChooser(intent, ""));

			break;
		case R.id.call:

			try {
				Intent callIntent = new Intent(Intent.ACTION_DIAL);
				callIntent.setData(Uri.parse("tel:4252048069"));
				callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(callIntent);
			} catch (ActivityNotFoundException activityException) {
				Log.e("Calling a Phone Number", "Call failed",
						activityException);
			}
		}
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (view != null) {
			ViewGroup parent = (ViewGroup) view.getParent();
			if (parent != null)
				parent.removeView(view);
		}
		try {
			view = inflater.inflate(R.layout.activity_contact, null);
		} catch (InflateException e) {

		}

		final Button sendEmail = (Button) view.findViewById(R.id.sendEmail);
		final Button call = (Button) view.findViewById(R.id.call);

		sendEmail.setOnClickListener(this);
		call.setOnClickListener(this);
		
		return view;
	}

}
